<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/table.css"/>
    <title>研报列表</title>
    <style type="text/css">
        .searcheBottom{margin-bottom: 10px;}
    </style>
</head>
<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote">
        <div class="demoTable">
            <div class="layui-inline searcheBottom">
                研报标题：
                <div class="layui-inline">
                    <input id="title" class="layui-input" name="title" autocomplete="off" placeholder="研报标题"/>
                </div>
            </div>
            <div class="layui-inline searcheBottom">
                频道：
                <div class="layui-inline">
                    <select  id="channelId" name="channelId" class="layui-input" lay-filter="select_filter" style="padding: 0px 20px;">
                    <option value="">全部</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline searcheBottom">
                <div class="layui-inline">
                    <label class="layui-form-label">提交时间:</label>
                    <div class="layui-input-inline">
                        <input id="startTime" class="layui-input" name="startTime" placeholder="开始日">
                    </div>
                    <div class="layui-input-inline">
                        &nbsp;-&nbsp;
                    </div>
                    <div class="layui-input-inline">
                        <input id="endTime" class="layui-input" name="endTime" placeholder="结束日">
                    </div>
                </div>
            </div>
            <div class="layui-inline searcheBottom">
                <button class="layui-btn" data-type="reload" id="search" >搜索</button>
                <a class="layui-btn layui-btn-primary" href="javascript:;" id="reset">重置</a>
                <a data-opt="add" href="/manage/research/researchReportAdd" class="layui-btn" id="addReport"><i class="layui-icon">&#xe608;</i>添加研报</a>
            </div>
        </div>
    </blockquote>
    <span style="font-size: 16px;"><b>研报列表</b></span>
    <table class="layui-hide" id="reportTable" lay-filter="tableFilter"></table>
</div>

<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script>
    layui.use(['jquery','table','laydate','layer','form','util','layedit'],function(){
        var $=layui.jquery,table=layui.table,laydate = layui.laydate,
            layer = layui.layer,form = layui.form,util=layui.util,layedit=layui.layedit;

        //下拉框
        loadSelect();
        function loadSelect(){
            $.ajax({
                url:"/manage/research/selchannlList",
                type:"get",
                dataType:"json",
                success:function(data){
                    var root = document.getElementById("channelId");
                    for(var i=0;i<data.length;i++){
                        var option = document.createElement("option");
                        option.innerHTML = data[i]["name"];
                        option.setAttribute("value",data[i]["id"]);
                        root.appendChild(option);
                        form.render("select");
                    }
                }
            })
        }

        //重置
        $("#reset").on("click",function(){
            title.value = '';
            channelId.value='';
            startTime.value = '';
            endTime.value = '';
        })

        //时间选择器
        var start = {
            max: '2099-06-16 23:59:59',
            format: 'yyyy-MM-dd HH:mm:ss',
            type: 'datetime',
            value: new Date(),
            show: true
            ,done: function(value){
                end.min = value; //开始日选好后，重置结束日的最小日期
                end.start = value //将结束日的初始值设定为开始日
            }
        };
        var end = {
            max: '2099-06-16 23:59:59',
            format: 'yyyy-MM-dd HH:mm:ss',
            type: 'datetime',
            value: new Date(),
            show: true
            ,done: function(value){
                start.max = value; //结束日选好后，重置开始日的最大日期
            }
        };
        $('#startTime').bind('click',function (){
            start.elem = this;
            start.closeStop = this
            laydate.render(start);
        });
        $('#endTime').bind('click',function (){
            end.elem = this;
            end.closeStop = this
            laydate.render(end);
        });
        //表格渲染
        table.render({
            elem:"#reportTable",
            url:"/manage/research/serchReportList",
            method:"post",
            where:{publishPlatform:''},
            cols:[[
                {field:'id', title: 'ID', sort: true,align:'center'},
                {field:'title', title: '名称',align:'center',templet:function (d) {
                    if(d.publishPlatform){
                        var publishPlatform = d.publishPlatform.replace(';','');
                        if(publishPlatform == '1'){
                            return d.title;
                        }else{
                            return d.appTitle;
                        }
                    }
                }},
                {field:'channelName', title: '频道',align:'center'},
                {field:'enableFlag', title: '状态',align:'center',
                    templet: function(d){
                        if(d.enableFlag==true){
                            return '<div class="layui-btn layui-bg-green layui-btn-xs">已发布</div>'
                        } else{
                            return '<div class="layui-btn layui-bg-gray layui-btn-xs">已下架</div>'
                        }
                    }
                },
                {field:'publishPlatform', title: '发布平台',align:'center',
                    templet: function(d){
                        if(d.publishPlatform){
                            var publishPlatform = d.publishPlatform.split(';');
                            var pls = '';
                            for(var i=0;i<publishPlatform.length;i++)
                                if('' != publishPlatform[i]){
                                    if(publishPlatform[i] =='1'){
                                        pls+= '<div class="layui-btn layui-bg-green layui-btn-xs">Web</div>'
                                    }else if(publishPlatform[i] =='2'){
                                        pls+= '<div class="layui-btn layui-btn-normal layui-btn-xs">App</div>'
                                    }
                                }
                            return pls;
                        }else{
                            return "";
                        }
                    }
                },
                {field:'setTop', title: '是否置顶',align:'center',
                    templet: function(d){
                        if(d.setTop == true){
                            return '<div class="layui-btn layui-bg-green layui-btn-xs">置顶</div>'
                        } else{
                            return '<div class="layui-btn layui-bg-gray layui-btn-xs">未置顶</div>'
                        }
                    }
                },
                {field:'createTime', title: '提交时间',sort: true,align:'center',
                    templet: function(d){
                        if(d.createTime!=null){
                            return util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss');
                        }else{
                            return "";
                        }
                    }
                },
                {field:'timingTime', title: '发布时间',sort: true,align:'center',
                    templet: function(d){
                        if(d.timingTime!=null){
                            return util.toDateString(d.timing_time, 'yyyy-MM-dd HH:mm:ss');
                        }else{
                            return "";
                        }
                    }
                },
                {field: 'tool', title:"操作",align:'left',width:280,align:'center',
                    templet:function(d){
                        var tool = '<a href="#" class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
                        if(d.enableFlag==true){
                            tool+='<a href="#" class="layui-btn layui-btn-warm layui-btn-xs" lay-event="enable">下架</a>';
                        }else{
                            tool+='<a href="#" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="enable">上架</a>';
                        }
                        if(d.setTop != true){
                            tool+='<a href="#" class="layui-btn layui-btn-xs" lay-event="top">设为置顶</a>';
                        }else{
                            tool+='<a href="#" class="layui-btn layui-btn-warm layui-btn-xs" lay-event="top">取消置顶</a>';
                        }
                        tool+='<a href="#" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                        return tool;
                    }
                }
            ]],
            limits:[10,15,20,25,30],
            limit:10,
            page:true
        });


        //表格重载
        var active = {
            reload: function () {
                var title = $('#title');
                var channelId = $('#channelId option:selected');
                var startTime = $('#startTime');
                var endTime = $('#endTime');
                table.reload('reportTable', {
                    where: {
                        title: title.val(),
                        channelId:channelId.val(),
                        startTime:startTime.val(),
                        endTime:endTime.val()
                    }
                });
            }
        };

        //将搜索框的值随请求传到后台
        $('.demoTable #search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $(".layui-input").keydown(function (e) {
            if(e.keyCode == 13){
                $('#search').click();
            }
        });

        //表格监听
        table.on('tool(tableFilter)', function(obj){
            var data = obj.data;
            if (obj.event == "enable") {
                var msg = '';
                if(data.enableFlag == true){
                    if(data.publishPlatform){
                        var publishPlatform = data.publishPlatform.replace(';','');
                        if(publishPlatform == '1'){
                            msg = '请确定是否下架《'+data.title+'》？下架后用户将无法查看已被分享的文章';
                        }else{
                            msg = '请确定是否下架《'+data.appTitle+'》？下架后用户将无法查看已被分享的文章';
                        }
                    }
                    layer.confirm(msg, { title:'文章下架'},function (index) {
                        $.ajax({
                            url:"/manage/research/enableReport",
                            type:"post",
                            dataType:"json",
                            data:{"id":data.id,"enableFlag":data.enableFlag},
                            success:function(count){
                                layer.close(index);
                                table.reload('reportTable');
                            }
                        })
                    });
                }else{
                    $.ajax({
                        url:"/manage/research/enableReport",
                        type:"post",
                        dataType:"json",
                        data:{"id":data.id,"enableFlag":data.enableFlag},
                        success:function(count){
                            table.reload('reportTable');
                        }
                    })
                }
            } else if (obj.event == "edit") {
                location.href='/manage/research/researchReportEdit?id='+data.id+'';
            } else if (obj.event == "del") {
                layer.confirm('确定删除么？', {icon: 7, title:'提示'},function (index) {
                    $.ajax({
                            url: "/manage/research/delelteReport",
                            type: "post",
                            data: { "researchId": data.id},
                            dataType: "json",
                            success: function (resData) {
                            	layer.alert(resData.msg, {
            	          		    skin: 'layui-layer-molv' //样式类名  自定义样式
            	          		    ,closeBtn: 1    // 是否显示关闭按钮
            	          		    ,anim: 1 //动画类型
            	          		    ,btn: ['确定'] //按钮
            	          		    ,icon: 1    // icon
            	          		    ,yes:function(){
                                        layer.closeAll();
            	          		    	if (resData.code >= 0) {
                                            table.reload('reportTable');
            	          	              }
            	          		    }});
                            }
                        },
                        function (index, item) {//删除操作后刷新页面
                            layer.closeAll();
                            table.reload('reportTable');
                    });
                });
            }else if(obj.event == "top"){
                $.ajax({
                    url:"/manage/research/researchSetTop",
                    type:"post",
                    dataType:"json",
                    data:{"id":data.id,"setTop":data.setTop},
                    success:function(){
                        table.reload('reportTable');
                    }
                })
            }
        });
    })
</script>




























</body>
</html>